<?php

declare(strict_types=1);

namespace app\admin\controller\dynamic;


use think\response\Json;
use app\admin\controller\Controller;

class Comment extends Controller
{
    protected $service = null;

    public function initialize()
    {
        parent::initialize();
        $this->service = new \app\admin\service\dynamic\CommentService();
    }

    /**
     * 列表
     * @return Json
     * @throws \think\db\exception\DbException
     */
    public function list(): Json
    {
        return success($this->service->list());
    }

    public function detail(int $id): Json
    {
        return success($this->service->detail($id));
    }

    public function create(): Json
    {
        return success('发布成功', $this->service->create(request()));
    }

    public function update($id = 0): Json
    {
        $id = (int)$id ?: request()->param('id/d', 0);
        if (!$id) {
            return error('参数错误: id不能为空');
        }
        return success('更新成功', $this->service->update($id, request()));
    }

    public function delete(int $id): Json
    {
        return $this->service->delete($id);
    }
}
